{
 "cells": [
  {
   "cell_type": "markdown",
   "metadata": {
    "slideshow": {
     "slide_type": "slide"
    }
   },
   "source": [
    "# Distributed Arrays"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 1,
   "metadata": {
    "slideshow": {
     "slide_type": "subslide"
    }
   },
   "outputs": [],
   "source": [
    "using JuliaRunClient"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "metadata": {
    "slideshow": {
     "slide_type": "subslide"
    }
   },
   "outputs": [
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      "\u001b[1m\u001b[36mINFO: \u001b[39m\u001b[22m\u001b[36mwaiting for 12...\n",
      "\u001b[39m\u001b[1m\u001b[36mINFO: \u001b[39m\u001b[22m\u001b[36mworkers started in 1.0016121864318848 seconds\n",
      "\u001b[39m"
     ]
    },
    {
     "data": {
      "text/plain": [
       "Dict{String,Any} with 2 entries:\n",
       "  \"data\" => JuliaRunClient for 12174009055273194445 @ http://juliarunremote-svc…\n",
       "  \"code\" => 0"
      ]
     },
     "execution_count": 4,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "initializeCluster(12)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 5,
   "metadata": {
    "slideshow": {
     "slide_type": "subslide"
    }
   },
   "outputs": [],
   "source": [
    "@everywhere using DistributedArrays"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 6,
   "metadata": {
    "slideshow": {
     "slide_type": "slide"
    }
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "12×12 DistributedArrays.DArray{Float64,2,Array{Float64,2}}:\n",
       " 0.0  0.0  0.0  0.0  0.0  0.0  0.0  0.0  0.0  0.0  0.0  0.0\n",
       " 0.0  0.0  0.0  0.0  0.0  0.0  0.0  0.0  0.0  0.0  0.0  0.0\n",
       " 0.0  0.0  0.0  0.0  0.0  0.0  0.0  0.0  0.0  0.0  0.0  0.0\n",
       " 0.0  0.0  0.0  0.0  0.0  0.0  0.0  0.0  0.0  0.0  0.0  0.0\n",
       " 0.0  0.0  0.0  0.0  0.0  0.0  0.0  0.0  0.0  0.0  0.0  0.0\n",
       " 0.0  0.0  0.0  0.0  0.0  0.0  0.0  0.0  0.0  0.0  0.0  0.0\n",
       " 0.0  0.0  0.0  0.0  0.0  0.0  0.0  0.0  0.0  0.0  0.0  0.0\n",
       " 0.0  0.0  0.0  0.0  0.0  0.0  0.0  0.0  0.0  0.0  0.0  0.0\n",
       " 0.0  0.0  0.0  0.0  0.0  0.0  0.0  0.0  0.0  0.0  0.0  0.0\n",
       " 0.0  0.0  0.0  0.0  0.0  0.0  0.0  0.0  0.0  0.0  0.0  0.0\n",
       " 0.0  0.0  0.0  0.0  0.0  0.0  0.0  0.0  0.0  0.0  0.0  0.0\n",
       " 0.0  0.0  0.0  0.0  0.0  0.0  0.0  0.0  0.0  0.0  0.0  0.0"
      ]
     },
     "execution_count": 6,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "a=dzeros(12,12)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 9,
   "metadata": {
    "slideshow": {
     "slide_type": "slide"
    }
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "12×12 DistributedArrays.DArray{Float64,2,Array{Float64,2}}:\n",
       " 5.0  5.0  5.0  5.0  5.0  5.0  5.0  5.0  5.0  5.0  5.0  5.0\n",
       " 5.0  5.0  5.0  5.0  5.0  5.0  5.0  5.0  5.0  5.0  5.0  5.0\n",
       " 5.0  5.0  5.0  5.0  5.0  5.0  5.0  5.0  5.0  5.0  5.0  5.0\n",
       " 5.0  5.0  5.0  5.0  5.0  5.0  5.0  5.0  5.0  5.0  5.0  5.0\n",
       " 5.0  5.0  5.0  5.0  5.0  5.0  5.0  5.0  5.0  5.0  5.0  5.0\n",
       " 5.0  5.0  5.0  5.0  5.0  5.0  5.0  5.0  5.0  5.0  5.0  5.0\n",
       " 5.0  5.0  5.0  5.0  5.0  5.0  5.0  5.0  5.0  5.0  5.0  5.0\n",
       " 5.0  5.0  5.0  5.0  5.0  5.0  5.0  5.0  5.0  5.0  5.0  5.0\n",
       " 5.0  5.0  5.0  5.0  5.0  5.0  5.0  5.0  5.0  5.0  5.0  5.0\n",
       " 5.0  5.0  5.0  5.0  5.0  5.0  5.0  5.0  5.0  5.0  5.0  5.0\n",
       " 5.0  5.0  5.0  5.0  5.0  5.0  5.0  5.0  5.0  5.0  5.0  5.0\n",
       " 5.0  5.0  5.0  5.0  5.0  5.0  5.0  5.0  5.0  5.0  5.0  5.0"
      ]
     },
     "execution_count": 9,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "a=dfill(5.0, 12, 12)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 10,
   "metadata": {
    "slideshow": {
     "slide_type": "slide"
    }
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "1000×1000 DistributedArrays.DArray{Float64,2,Array{Float64,2}}:\n",
       " 0.403691   0.46897    0.457739   …  0.0349636  0.5117    0.919109  \n",
       " 0.606375   0.713249   0.267151      0.975594   0.498865  0.679318  \n",
       " 0.116209   0.484542   0.0740582     0.693086   0.380569  0.610809  \n",
       " 0.957405   0.132701   0.796273      0.0982588  0.329043  0.587064  \n",
       " 0.647431   0.387348   0.371503      0.964483   0.883691  0.290433  \n",
       " 0.808158   0.0031073  0.0769654  …  0.529958   0.421581  0.194169  \n",
       " 0.750994   0.0830387  0.586153      0.236443   0.60161   0.715128  \n",
       " 0.48328    0.956374   0.267884      0.189519   0.584099  0.620797  \n",
       " 0.26709    0.0332169  0.596844      0.116999   0.315768  0.858921  \n",
       " 0.0991286  0.784457   0.473792      0.3841     0.828818  0.798312  \n",
       " 0.870114   0.414957   0.352108   …  0.39121    0.588872  0.690426  \n",
       " 0.753054   0.0592712  0.567508      0.699352   0.630008  0.609589  \n",
       " 0.0954168  0.461987   0.69267       0.972445   0.919628  0.00938234\n",
       " ⋮                                ⋱                                 \n",
       " 0.109184   0.0619804  0.341727      0.88037    0.901905  0.504424  \n",
       " 0.329636   0.50736    0.794156      0.810934   0.320996  0.676332  \n",
       " 0.254326   0.497662   0.880717   …  0.865391   0.412506  0.428884  \n",
       " 0.793624   0.217944   0.0588519     0.461469   0.254533  0.549575  \n",
       " 0.0797438  0.18119    0.8094        0.268266   0.230308  0.404944  \n",
       " 0.906887   0.900372   0.489162      0.672802   0.258364  0.0790615 \n",
       " 0.774536   0.0506145  0.763811      0.884354   0.611139  0.324233  \n",
       " 0.519821   0.415316   0.121587   …  0.530883   0.794905  0.998794  \n",
       " 0.455937   0.442201   0.109067      0.16433    0.893643  0.101848  \n",
       " 0.824855   0.135224   0.822955      0.393285   0.869446  0.0974648 \n",
       " 0.439931   0.696338   0.952335      0.616934   0.83331   0.465221  \n",
       " 0.15059    0.590202   0.118794      0.473408   0.764071  0.429095  "
      ]
     },
     "execution_count": 10,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "b=drand(1000,1000)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 21,
   "metadata": {
    "slideshow": {
     "slide_type": "slide"
    }
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "4×3 Array{Int64,2}:\n",
       " 2  6  10\n",
       " 3  7  11\n",
       " 4  8  12\n",
       " 5  9  13"
      ]
     },
     "execution_count": 21,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "procs(b)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 31,
   "metadata": {
    "slideshow": {
     "slide_type": "slide"
    }
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "  0.002660 seconds (1.01 k allocations: 101.594 KiB)\n"
     ]
    },
    {
     "data": {
      "text/plain": [
       "500139.7311256226"
      ]
     },
     "execution_count": 31,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "@time sum(b)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 12,
   "metadata": {
    "slideshow": {
     "slide_type": "slide"
    }
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "12×12 Array{Float64,2}:\n",
       " 5.0  5.0  5.0  5.0  5.0  5.0  5.0  5.0  5.0  5.0  5.0  5.0\n",
       " 5.0  5.0  5.0  5.0  5.0  5.0  5.0  5.0  5.0  5.0  5.0  5.0\n",
       " 5.0  5.0  5.0  5.0  5.0  5.0  5.0  5.0  5.0  5.0  5.0  5.0\n",
       " 5.0  5.0  5.0  5.0  5.0  5.0  5.0  5.0  5.0  5.0  5.0  5.0\n",
       " 5.0  5.0  5.0  5.0  5.0  5.0  5.0  5.0  5.0  5.0  5.0  5.0\n",
       " 5.0  5.0  5.0  5.0  5.0  5.0  5.0  5.0  5.0  5.0  5.0  5.0\n",
       " 5.0  5.0  5.0  5.0  5.0  5.0  5.0  5.0  5.0  5.0  5.0  5.0\n",
       " 5.0  5.0  5.0  5.0  5.0  5.0  5.0  5.0  5.0  5.0  5.0  5.0\n",
       " 5.0  5.0  5.0  5.0  5.0  5.0  5.0  5.0  5.0  5.0  5.0  5.0\n",
       " 5.0  5.0  5.0  5.0  5.0  5.0  5.0  5.0  5.0  5.0  5.0  5.0\n",
       " 5.0  5.0  5.0  5.0  5.0  5.0  5.0  5.0  5.0  5.0  5.0  5.0\n",
       " 5.0  5.0  5.0  5.0  5.0  5.0  5.0  5.0  5.0  5.0  5.0  5.0"
      ]
     },
     "execution_count": 12,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "convert(Array{Float64}, a)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 24,
   "metadata": {
    "slideshow": {
     "slide_type": "slide"
    }
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "search: \u001b[1mD\u001b[22m\u001b[1mA\u001b[22m\u001b[1mr\u001b[22m\u001b[1mr\u001b[22m\u001b[1ma\u001b[22m\u001b[1my\u001b[22m @\u001b[1mD\u001b[22m\u001b[1mA\u001b[22m\u001b[1mr\u001b[22m\u001b[1mr\u001b[22m\u001b[1ma\u001b[22m\u001b[1my\u001b[22m Sub\u001b[1mD\u001b[22m\u001b[1mA\u001b[22m\u001b[1mr\u001b[22m\u001b[1mr\u001b[22m\u001b[1ma\u001b[22m\u001b[1my\u001b[22m SubOr\u001b[1mD\u001b[22m\u001b[1mA\u001b[22m\u001b[1mr\u001b[22m\u001b[1mr\u001b[22m\u001b[1ma\u001b[22m\u001b[1my\u001b[22m Share\u001b[1md\u001b[22m\u001b[1mA\u001b[22m\u001b[1mr\u001b[22m\u001b[1mr\u001b[22m\u001b[1ma\u001b[22m\u001b[1my\u001b[22m Stri\u001b[1md\u001b[22med\u001b[1mA\u001b[22m\u001b[1mr\u001b[22m\u001b[1mr\u001b[22m\u001b[1ma\u001b[22m\u001b[1my\u001b[22m \u001b[1mD\u001b[22mense\u001b[1mA\u001b[22m\u001b[1mr\u001b[22m\u001b[1mr\u001b[22m\u001b[1ma\u001b[22m\u001b[1my\u001b[22m\n",
      "\n"
     ]
    },
    {
     "data": {
      "text/markdown": [
       "```\n",
       "DArray(init, dims, [procs, dist])\n",
       "```\n",
       "\n",
       "Construct a distributed array.\n",
       "\n",
       "The parameter `init` is a function that accepts a tuple of index ranges. This function should allocate a local chunk of the distributed array and initialize it for the specified indices.\n",
       "\n",
       "`dims` is the overall size of the distributed array.\n",
       "\n",
       "`procs` optionally specifies a vector of process IDs to use. If unspecified, the array is distributed over all worker processes only. Typically, when running in distributed mode, i.e., nprocs() > 1, this would mean that no chunk of the distributed array exists on the process hosting the interactive julia prompt.\n",
       "\n",
       "`dist` is an integer vector specifying how many chunks the distributed array should be divided into in each dimension.\n",
       "\n",
       "For example, the `dfill` function that creates a distributed array and fills it with a value `v` is implemented as:\n",
       "\n",
       "### Example\n",
       "\n",
       "```jl\n",
       "dfill(v, args...) = DArray(I->fill(v, map(length,I)), args...)\n",
       "```\n"
      ],
      "text/plain": [
       "```\n",
       "DArray(init, dims, [procs, dist])\n",
       "```\n",
       "\n",
       "Construct a distributed array.\n",
       "\n",
       "The parameter `init` is a function that accepts a tuple of index ranges. This function should allocate a local chunk of the distributed array and initialize it for the specified indices.\n",
       "\n",
       "`dims` is the overall size of the distributed array.\n",
       "\n",
       "`procs` optionally specifies a vector of process IDs to use. If unspecified, the array is distributed over all worker processes only. Typically, when running in distributed mode, i.e., nprocs() > 1, this would mean that no chunk of the distributed array exists on the process hosting the interactive julia prompt.\n",
       "\n",
       "`dist` is an integer vector specifying how many chunks the distributed array should be divided into in each dimension.\n",
       "\n",
       "For example, the `dfill` function that creates a distributed array and fills it with a value `v` is implemented as:\n",
       "\n",
       "### Example\n",
       "\n",
       "```jl\n",
       "dfill(v, args...) = DArray(I->fill(v, map(length,I)), args...)\n",
       "```\n"
      ]
     },
     "execution_count": 24,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "?DArray"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 17,
   "metadata": {
    "slideshow": {
     "slide_type": "slide"
    }
   },
   "outputs": [],
   "source": [
    "@everywhere function par(I)\n",
    "    # create our local patch\n",
    "    # I is a tuple of intervals, each interval is\n",
    "    # regarded as a 1D array with integer entries\n",
    "    # size(I[1], 1) gives the number of entries in I[1]\n",
    "    # size(I[2], 1) gives the number of entries in I[2]\n",
    "    d=(size(I[1], 1), size(I[2], 1))\n",
    "    m = fill(myid(), d)\n",
    "    return m\n",
    "end"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 38,
   "metadata": {
    "slideshow": {
     "slide_type": "slide"
    }
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "800×800 DistributedArrays.DArray{Int64,2,Array{Int64,2}}:\n",
       " 2  2  2  2  2  2  2  2  2  2  2  2  2  …  10  10  10  10  10  10  10  10  10\n",
       " 2  2  2  2  2  2  2  2  2  2  2  2  2     10  10  10  10  10  10  10  10  10\n",
       " 2  2  2  2  2  2  2  2  2  2  2  2  2     10  10  10  10  10  10  10  10  10\n",
       " 2  2  2  2  2  2  2  2  2  2  2  2  2     10  10  10  10  10  10  10  10  10\n",
       " 2  2  2  2  2  2  2  2  2  2  2  2  2     10  10  10  10  10  10  10  10  10\n",
       " 2  2  2  2  2  2  2  2  2  2  2  2  2  …  10  10  10  10  10  10  10  10  10\n",
       " 2  2  2  2  2  2  2  2  2  2  2  2  2     10  10  10  10  10  10  10  10  10\n",
       " 2  2  2  2  2  2  2  2  2  2  2  2  2     10  10  10  10  10  10  10  10  10\n",
       " 2  2  2  2  2  2  2  2  2  2  2  2  2     10  10  10  10  10  10  10  10  10\n",
       " 2  2  2  2  2  2  2  2  2  2  2  2  2     10  10  10  10  10  10  10  10  10\n",
       " 2  2  2  2  2  2  2  2  2  2  2  2  2  …  10  10  10  10  10  10  10  10  10\n",
       " 2  2  2  2  2  2  2  2  2  2  2  2  2     10  10  10  10  10  10  10  10  10\n",
       " 2  2  2  2  2  2  2  2  2  2  2  2  2     10  10  10  10  10  10  10  10  10\n",
       " ⋮              ⋮              ⋮        ⋱                   ⋮                \n",
       " 5  5  5  5  5  5  5  5  5  5  5  5  5     13  13  13  13  13  13  13  13  13\n",
       " 5  5  5  5  5  5  5  5  5  5  5  5  5     13  13  13  13  13  13  13  13  13\n",
       " 5  5  5  5  5  5  5  5  5  5  5  5  5  …  13  13  13  13  13  13  13  13  13\n",
       " 5  5  5  5  5  5  5  5  5  5  5  5  5     13  13  13  13  13  13  13  13  13\n",
       " 5  5  5  5  5  5  5  5  5  5  5  5  5     13  13  13  13  13  13  13  13  13\n",
       " 5  5  5  5  5  5  5  5  5  5  5  5  5     13  13  13  13  13  13  13  13  13\n",
       " 5  5  5  5  5  5  5  5  5  5  5  5  5     13  13  13  13  13  13  13  13  13\n",
       " 5  5  5  5  5  5  5  5  5  5  5  5  5  …  13  13  13  13  13  13  13  13  13\n",
       " 5  5  5  5  5  5  5  5  5  5  5  5  5     13  13  13  13  13  13  13  13  13\n",
       " 5  5  5  5  5  5  5  5  5  5  5  5  5     13  13  13  13  13  13  13  13  13\n",
       " 5  5  5  5  5  5  5  5  5  5  5  5  5     13  13  13  13  13  13  13  13  13\n",
       " 5  5  5  5  5  5  5  5  5  5  5  5  5     13  13  13  13  13  13  13  13  13"
      ]
     },
     "execution_count": 38,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "m = DArray(par, (800, 800))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 33,
   "metadata": {
    "slideshow": {
     "slide_type": "subslide"
    }
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "4×3 Array{Tuple{UnitRange{Int64},UnitRange{Int64}},2}:\n",
       " (1:200, 1:267)    (1:200, 268:533)    (1:200, 534:800)  \n",
       " (201:400, 1:267)  (201:400, 268:533)  (201:400, 534:800)\n",
       " (401:600, 1:267)  (401:600, 268:533)  (401:600, 534:800)\n",
       " (601:800, 1:267)  (601:800, 268:533)  (601:800, 534:800)"
      ]
     },
     "execution_count": 33,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "m.indexes"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 37,
   "metadata": {
    "slideshow": {
     "slide_type": "slide"
    }
   },
   "outputs": [
    {
     "ename": "LoadError",
     "evalue": "\u001b[91mMethodError: no method matching svdvals!(::DistributedArrays.DArray{Float64,2,Array{Float64,2}})\u001b[0m\nClosest candidates are:\n  svdvals!(\u001b[91m::Union{Base.ReshapedArray{T<:Union{Complex{Float32}, Complex{Float64}, Float32, Float64},2,A,MI} where MI<:Tuple{Vararg{Base.MultiplicativeInverses.SignedMultiplicativeInverse{Int64},N} where N} where A<:Union{DenseArray, SubArray{T,N,P,I,true} where I<:Tuple{Union{Base.Slice, UnitRange},Vararg{Any,N} where N} where P where N where T}, DenseArray{T<:Union{Complex{Float32}, Complex{Float64}, Float32, Float64},2}, SubArray{T<:Union{Complex{Float32}, Complex{Float64}, Float32, Float64},2,A,I,L} where L} where I<:Tuple{Vararg{Union{Base.AbstractCartesianIndex, Int64, Range{Int64}},N} where N} where A<:Union{Base.ReshapedArray{T,N,A,MI} where MI<:Tuple{Vararg{Base.MultiplicativeInverses.SignedMultiplicativeInverse{Int64},N} where N} where A<:Union{DenseArray, SubArray{T,N,P,I,true} where I<:Tuple{Union{Base.Slice, UnitRange},Vararg{Any,N} where N} where P where N where T} where N where T, DenseArray}\u001b[39m) where T<:Union{Complex{Float32}, Complex{Float64}, Float32, Float64} at linalg/svd.jl:130\n  svdvals!(\u001b[91m::Union{Base.ReshapedArray{T<:Union{Complex{Float32}, Complex{Float64}, Float32, Float64},2,A,MI} where MI<:Tuple{Vararg{Base.MultiplicativeInverses.SignedMultiplicativeInverse{Int64},N} where N} where A<:Union{DenseArray, SubArray{T,N,P,I,true} where I<:Tuple{Union{Base.Slice, UnitRange},Vararg{Any,N} where N} where P where N where T}, DenseArray{T<:Union{Complex{Float32}, Complex{Float64}, Float32, Float64},2}, SubArray{T<:Union{Complex{Float32}, Complex{Float64}, Float32, Float64},2,A,I,L} where L} where I<:Tuple{Vararg{Union{Base.AbstractCartesianIndex, Int64, Range{Int64}},N} where N} where A<:Union{Base.ReshapedArray{T,N,A,MI} where MI<:Tuple{Vararg{Base.MultiplicativeInverses.SignedMultiplicativeInverse{Int64},N} where N} where A<:Union{DenseArray, SubArray{T,N,P,I,true} where I<:Tuple{Union{Base.Slice, UnitRange},Vararg{Any,N} where N} where P where N where T} where N where T, DenseArray}\u001b[39m, \u001b[91m::Union{Base.ReshapedArray{T<:Union{Complex{Float32}, Complex{Float64}, Float32, Float64},2,A,MI} where MI<:Tuple{Vararg{Base.MultiplicativeInverses.SignedMultiplicativeInverse{Int64},N} where N} where A<:Union{DenseArray, SubArray{T,N,P,I,true} where I<:Tuple{Union{Base.Slice, UnitRange},Vararg{Any,N} where N} where P where N where T}, DenseArray{T<:Union{Complex{Float32}, Complex{Float64}, Float32, Float64},2}, SubArray{T<:Union{Complex{Float32}, Complex{Float64}, Float32, Float64},2,A,I,L} where L} where I<:Tuple{Vararg{Union{Base.AbstractCartesianIndex, Int64, Range{Int64}},N} where N} where A<:Union{Base.ReshapedArray{T,N,A,MI} where MI<:Tuple{Vararg{Base.MultiplicativeInverses.SignedMultiplicativeInverse{Int64},N} where N} where A<:Union{DenseArray, SubArray{T,N,P,I,true} where I<:Tuple{Union{Base.Slice, UnitRange},Vararg{Any,N} where N} where P where N where T} where N where T, DenseArray}\u001b[39m) where T<:Union{Complex{Float32}, Complex{Float64}, Float32, Float64} at linalg/svd.jl:289\n  svdvals!(\u001b[91m::Union{Hermitian{Complex{T},S}, Hermitian{T,S}, Symmetric{T,S}} where S where T<:Real\u001b[39m) at linalg/symmetric.jl:456\n  ...\u001b[39m",
     "output_type": "error",
     "traceback": [
      "\u001b[91mMethodError: no method matching svdvals!(::DistributedArrays.DArray{Float64,2,Array{Float64,2}})\u001b[0m\nClosest candidates are:\n  svdvals!(\u001b[91m::Union{Base.ReshapedArray{T<:Union{Complex{Float32}, Complex{Float64}, Float32, Float64},2,A,MI} where MI<:Tuple{Vararg{Base.MultiplicativeInverses.SignedMultiplicativeInverse{Int64},N} where N} where A<:Union{DenseArray, SubArray{T,N,P,I,true} where I<:Tuple{Union{Base.Slice, UnitRange},Vararg{Any,N} where N} where P where N where T}, DenseArray{T<:Union{Complex{Float32}, Complex{Float64}, Float32, Float64},2}, SubArray{T<:Union{Complex{Float32}, Complex{Float64}, Float32, Float64},2,A,I,L} where L} where I<:Tuple{Vararg{Union{Base.AbstractCartesianIndex, Int64, Range{Int64}},N} where N} where A<:Union{Base.ReshapedArray{T,N,A,MI} where MI<:Tuple{Vararg{Base.MultiplicativeInverses.SignedMultiplicativeInverse{Int64},N} where N} where A<:Union{DenseArray, SubArray{T,N,P,I,true} where I<:Tuple{Union{Base.Slice, UnitRange},Vararg{Any,N} where N} where P where N where T} where N where T, DenseArray}\u001b[39m) where T<:Union{Complex{Float32}, Complex{Float64}, Float32, Float64} at linalg/svd.jl:130\n  svdvals!(\u001b[91m::Union{Base.ReshapedArray{T<:Union{Complex{Float32}, Complex{Float64}, Float32, Float64},2,A,MI} where MI<:Tuple{Vararg{Base.MultiplicativeInverses.SignedMultiplicativeInverse{Int64},N} where N} where A<:Union{DenseArray, SubArray{T,N,P,I,true} where I<:Tuple{Union{Base.Slice, UnitRange},Vararg{Any,N} where N} where P where N where T}, DenseArray{T<:Union{Complex{Float32}, Complex{Float64}, Float32, Float64},2}, SubArray{T<:Union{Complex{Float32}, Complex{Float64}, Float32, Float64},2,A,I,L} where L} where I<:Tuple{Vararg{Union{Base.AbstractCartesianIndex, Int64, Range{Int64}},N} where N} where A<:Union{Base.ReshapedArray{T,N,A,MI} where MI<:Tuple{Vararg{Base.MultiplicativeInverses.SignedMultiplicativeInverse{Int64},N} where N} where A<:Union{DenseArray, SubArray{T,N,P,I,true} where I<:Tuple{Union{Base.Slice, UnitRange},Vararg{Any,N} where N} where P where N where T} where N where T, DenseArray}\u001b[39m, \u001b[91m::Union{Base.ReshapedArray{T<:Union{Complex{Float32}, Complex{Float64}, Float32, Float64},2,A,MI} where MI<:Tuple{Vararg{Base.MultiplicativeInverses.SignedMultiplicativeInverse{Int64},N} where N} where A<:Union{DenseArray, SubArray{T,N,P,I,true} where I<:Tuple{Union{Base.Slice, UnitRange},Vararg{Any,N} where N} where P where N where T}, DenseArray{T<:Union{Complex{Float32}, Complex{Float64}, Float32, Float64},2}, SubArray{T<:Union{Complex{Float32}, Complex{Float64}, Float32, Float64},2,A,I,L} where L} where I<:Tuple{Vararg{Union{Base.AbstractCartesianIndex, Int64, Range{Int64}},N} where N} where A<:Union{Base.ReshapedArray{T,N,A,MI} where MI<:Tuple{Vararg{Base.MultiplicativeInverses.SignedMultiplicativeInverse{Int64},N} where N} where A<:Union{DenseArray, SubArray{T,N,P,I,true} where I<:Tuple{Union{Base.Slice, UnitRange},Vararg{Any,N} where N} where P where N where T} where N where T, DenseArray}\u001b[39m) where T<:Union{Complex{Float32}, Complex{Float64}, Float32, Float64} at linalg/svd.jl:289\n  svdvals!(\u001b[91m::Union{Hermitian{Complex{T},S}, Hermitian{T,S}, Symmetric{T,S}} where S where T<:Real\u001b[39m) at linalg/symmetric.jl:456\n  ...\u001b[39m",
      "",
      "Stacktrace:",
      " [1] \u001b[1msvdvals\u001b[22m\u001b[22m\u001b[1m(\u001b[22m\u001b[22m::DistributedArrays.DArray{Int64,2,Array{Int64,2}}\u001b[1m)\u001b[22m\u001b[22m at \u001b[1m./linalg/svd.jl:158\u001b[22m\u001b[22m",
      " [2] \u001b[1mrank\u001b[22m\u001b[22m\u001b[1m(\u001b[22m\u001b[22m::DistributedArrays.DArray{Int64,2,Array{Int64,2}}\u001b[1m)\u001b[22m\u001b[22m at \u001b[1m./linalg/generic.jl:725\u001b[22m\u001b[22m"
     ]
    }
   ],
   "source": [
    "rank(m)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 35,
   "metadata": {
    "slideshow": {
     "slide_type": "subslide"
    }
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "1"
      ]
     },
     "execution_count": 35,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "mm = @spawnat 2 rank(localpart(m))\n",
    "fetch(mm)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {
    "slideshow": {
     "slide_type": "slide"
    }
   },
   "source": [
    "#### Credits\n",
    "  * http://www.csd.uwo.ca/~moreno/cs2101a_moreno/Parallel_computing_with_Julia.pdf\n",
    "  * "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {
    "slideshow": {
     "slide_type": "skip"
    }
   },
   "outputs": [],
   "source": [
    "releaseCluster()"
   ]
  }
 ],
 "metadata": {
  "celltoolbar": "Slideshow",
  "kernelspec": {
   "display_name": "Julia 0.6.2",
   "language": "julia",
   "name": "julia-0.6"
  },
  "language_info": {
   "file_extension": ".jl",
   "mimetype": "application/julia",
   "name": "julia",
   "version": "0.6.2"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 2
}
